package day14.com.zhiyou100;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class Demo07 {

    public static void main(String[] args) {
        // 先自定义一个比较器对象
        Comparator c = new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.score - o2.score;
            }
        };
        // 把比较器传入进去
        Set<Student> set = new TreeSet<>(c);// 保证了Student是有序的
        set.add(new Student("009","张三1",90));
        set.add(new Student("003","张三",80));
        set.add(new Student("008","张三8",100));
        set.add(new Student("005","张三5",70));
        set.add(new Student("004","张三7",50));
        System.out.println(set);

    }
}
